<?php
namespace app\home\controller;

use app\home\common\Common;
use app\home\common\Page;
use app\home\common\Pagetwo;
use app\home\service\Smstmp;
use app\infrastructure\uri\Request;
use app\infrastructure\uri\Uri;
use Monolog\Handler\DynamoDbHandler;

/**
 * Created by PhpStorm.
 * User: YD
 * Date: 2017/4/26
 * Time: 16:52
 */
class Due extends Common
{
    private $client;
    public  function  __construct(){
        parent::__construct();
        $this->client=new Request();
    }
    public function dueList()
    {
        $get=$_GET;
        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$get['dueDay'];
        }else{
            $url=Uri::HOST.Uri::SELECTDUELIST;
        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
         //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
           $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                   if($v['dueDay'] >= 0){
                       $dueNewDate[]=$v;
                   }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }
    public function dueAllList()
    {
        $get=$_GET;
        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$get['dueDay'];
        }else{
            $url=Uri::HOST.Uri::SELECTDUELIST;
        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
         //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
           $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                       $dueNewDate[]=$v;
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                        $dueNewDate[]=$v;
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }

    /**
     * 逾期三天的借款
     */
    public function dueTwoList()
    {
        $get=$_GET;
        $day=-3;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    $dueNewDate[]=$v;
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    $dueNewDate[]=$v;
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        $phone=[];
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        return view();
    }

    /**
     * 还有两天逾期
     */
    public function dueOneList()
    {
        $get=$_GET;
        $day=-2;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
        $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                        $dueNewDate[]=$v;
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                        $dueNewDate[]=$v;
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        $phone=[];
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        return view();
    }

    /**
     * 已到还款日用户
     */
    public function dueTodayList(){
        $get=$_GET;
        $day=-1;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
        $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    $dueNewDate[]=$v;
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    $dueNewDate[]=$v;
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        $phone=[];
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        return view();
    }

    /**
     * 逾期一天
     */
    public function dueOneDay(){
        $get=$_GET;
        $day=1;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }

    /**
     * 逾期三天
     */
    public function dueThreeDay(){
        $get=$_GET;
        $day=3;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }

    /**
     * 逾期四天
     */
    public function dueFourDay(){
        $get=$_GET;
        $day=4;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }

    /**
     * 逾期五天
     */
    public function dueFiveDay(){
        $get=$_GET;
        $day=5;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$day;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 0){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }

    /**
     * 坏账列表
     */
    public function dueBadList(){
        $get=$_GET;
        $day=0;
//        if(isset($get['dueDay']) && !empty($get['dueDay'])){
        $url=Uri::HOST.Uri::SELECTDUEBAD;
//        }else{
//            $url=Uri::HOST.Uri::SELECTDUELIST;
//        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueData['data']);
            $this->extendToExcel($data);
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueData['data'] as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueData['data'][$k];
                }
            }
            $dueData['data']=$newData;
        }
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        $phone=[];
        if(!empty($dueData['data'])){
            foreach($dueData['data'] as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $this->assign('data',$dueData['data']);
        return view();
    }

    /**
     * 逾期五天以上列表
     */
    public function dueMoreFiveDay(){
        $get=$_GET;
        if(isset($get['dueDay']) && !empty($get['dueDay'])){
            $url=Uri::HOST.Uri::SELECTDUELISTBYDAY.$get['dueDay'];
        }else{
            $url=Uri::HOST.Uri::SELECTDUELIST;
        }
        $dueData=$this->client->getArrayData($url);
//        dd($dueData);
        //读取短信模板
//        $smsTmp=require("./smsTmp.php");
        $tmpUrl=Uri::HOST.Uri::SELECTSMSTMP.'?is_valid=1&plantForm=1';
        $smsTmp=$this->client->getArrayData($tmpUrl);
        if($smsTmp['code'] != 0){
            $smsTmp=[];
        }else{
            $smsTmp=$smsTmp['data'];
        }
        $this->assign('smsTmp',$smsTmp);
        $appSmsTmp=(new Smstmp())->getAppSmsTmp(2);
        $this->assign('appSmsTmp',$appSmsTmp);
        //语音推送模板
        $smsVoiceTmp=(new Smstmp())->getAppSmsTmp(3);
        $this->assign('smsVoiceTmp',$smsVoiceTmp);
        $phone=[];
        foreach($dueData['data'] as $k=>$v){
            $dueData['data'][$k]['repayDate']=date('Y-m-d',($v['loanArrangedTime']/1000 + ($v['loanRepayPeriod']-1)*24*3600));
        }
        $dueNewDate=[];
        $indiaPhone="/^[0-9][0-9]{8}[0-9]$/";
        $indiaPhone2="/^[1]{7}[0-9]{2}[0-9]$/";
        $chinaPhone="/^[1][0-9]{9}[0-9]$/";
        foreach($dueData['data'] as $k=>$v){
            if(session('role') == 'admin'){
                if(preg_match($indiaPhone,$v['userPhone']) && !preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 6){
                        $dueNewDate[]=$v;
                    }
                }
            }else if(session('role') == 'testing'){
                if(preg_match($chinaPhone,$v['userPhone']) || preg_match($indiaPhone2,$v['userPhone'])){
                    if($v['dueDay'] >= 6){
                        $dueNewDate[]=$v;
                    }
                }
            }
        }
        if(isset($get['userPhone']) && !empty($get['userPhone'])){
            $newData=[];
            foreach($dueNewDate as $k=>$v){
                if($v['userPhone'] == $get['userPhone']){
                    $newData[]=$dueNewDate[$k];
                }
            }
            $dueNewDate=$newData;
        }
        $this->assign('data',$dueNewDate);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userID',
                    'userPhone',
                    'transactionID',
                    'transactionStatus',
                    'productID',
                    'loanAmount',
                    'loanRepayPeriod',
                    'managementFee',
                    'loanInterestRate',
                    'actualAmount',
                    'couponID',
                    'userStatus',
                    'auditProcessID',
                    'auditProcessStatus',
                    'loanSubmitTime',
                    'loanArrangedTime',
                    'loanRepayStatus',
                    'auditFee',
                    'totalRepay',
                    'overdueRate',
                    'sort',
                    'createdAt',
                    'updatedAt',
                    'dueDay',
                    'duefee'
                ]
            ];
            $data = array_merge($column_name, $dueNewDate);
            $this->extendToExcel($data);
        }
        if(!empty($dueNewDate)){
            foreach($dueNewDate as $k=>$v){
                $phone[]=[
                    "phone"=>$v['userPhone'],
                    "dueDay"=>$v['dueDay'],
                    'repayTime'=>$v['loanArrangedTime'],
                    'userID'=>$v['userID'],
                    'totalRepay'=>$v['duefee'] + $v['totalRepay'],
                    'loanRepayPeriod'=>$v['loanRepayPeriod']
                ];
            }
        }else{
            $phone=[];
        }
        $phone=json_encode($phone);
        $this->assign('phone',$phone);
        return view();
    }
}


















